import type {
  UserLoginMenu,
  UserLoginParams,
  UserSSOLoginParams,
  UserLoginResult,
} from './types/login.type'
import { mockService, service } from '@/service'

enum Api {
  Login = 'hbsys-system/login',
  SSOLogin = 'user/sso-login',
  Signin = 'user/signin',
  Logout = 'hbsys-system/logout',
  Menu = 'user/menu',
  Permissions = 'user/permissions',
  GetInfo = 'hbsys-system/menu/treeselect',
  ChangeRole = 'hbsys-system/user/changeRole',
  YKBLogin = `hbsys-system/sorg/info/getYKBUser`,
}

export const ChangeRoleApi = (roleId: any) => {
  return service.request<any>({
    url: Api.ChangeRole + `/${roleId}`,
    method: 'get'
  })
}

export const userLogin = (data: UserLoginParams) => {
  return service.request<any>({
    url: Api.Login,
    method: 'POST',
    data,
    isLogin: true
  })
}

export const getInfo = (params: any) => {
  return service.request<any>({
    url: Api.GetInfo,
    method: 'GET',
    params
  })
}

// 愉快办登录 
export const userYKBLogin = (authCode) => {
  return service.request({
    url: `${Api.YKBLogin}/${authCode}`,
    method: 'GET'
  })
}

export const userSSOLogin = (data: UserSSOLoginParams) => {
  return mockService.request<Service.Result<UserLoginResult>>({
    url: Api.SSOLogin,
    method: 'POST',
    data
  })
}

// 注册
export const userSignin = (data: any) => {
  return mockService.request({
    url: Api.Signin,
    method: 'POST',
    data
  })
}

// 退出登录
export const userLogout = () => {
  return mockService.request({
    url: Api.Logout,
    method: 'POST'
  })
}

// 用户菜单
export const getUserMenu = () => {
  return mockService.request<Service.Result<UserLoginMenu[]>>({
    url: Api.Menu,
    method: 'GET'
  })
}



// 用户按钮权限
export const getUserPermissions = (params?:any) => {
  // return mockService.request<Service.Result<string[]>>({
  //   url: Api.Permissions,
  //   method: 'GET'
  // })
  return getInfo(params)
}

export * from './types/login.type'
